import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { DailyTitleBar } from "../titleBar/DailyTitleBar";
import { DailyListBody } from "./DailyListBody";
import { GScrollPane } from "../../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { DailyAwardList } from "../reward/DailyAwardList";
import { DailyItem } from "../item/DailyItem";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { DailyRule } from "../../../rules/DailyRule";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class DailyListNormal
    
    export  class DailyListNormal /* flash.display.Sprite */
    {
        constructor()
        {
            
            mouseEnabled = false;
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            this.initWidth();
            this._bg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._bg.width = this._listWidth;
            this._bg.height = this._height;
            addChild(this._bg);
            this.createTitleBar();
            this.createListBody();
            this.createAwardList();
            return;
        }

        protected initWidth(): void
        {
            this._titleWidth = 450;
            this._listWidth = 450;
            this._listHeight = 370;
            return;
        }

        protected createTitleBar(): void
        {
            this._titleBar = new DailyTitleBar(this._titleWidth);
            this._titleBar.x = 20;
            this._titleBar.y = 5;
            addChild(this._titleBar);
            return;
        }

        protected createListBody(): void
        {
            this._bodySprite = new DailyListBody();
            this._bodySprite.addEventListener(flash.events.MouseEvent.CLICK, this.onItemListClickHandler);
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = 5;
            this._scrollPane.y = 29;
            this._scrollPane.width = this._listWidth - 10;
            this._scrollPane.height = this._listHeight;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.source = this._bodySprite;
            this._scrollPane.scrollDrag = false;
            this._scrollPane.focusEnabled = false;
            addChild(this._scrollPane);
            return;
        }

        protected createAwardList(): void
        {
            this._dailyAwardList = new DailyAwardList(this.width - this._listWidth - 4, this.height);
            this._dailyAwardList.x = this._listWidth + 4;
            this._dailyAwardList.y = 0;
            addChild(this._dailyAwardList);
            return;
        }

        protected onItemListClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as DailyItem;
            if (loc1 && !(loc1 == this._lastItem)) 
            {
                loc1.mouseDown(true);
                if (this._dailyAwardList && this._dailyAwardList.parent) 
                {
                    this._dailyAwardList.updateData(loc1.info);
                }
                if (this._lastItem) 
                {
                    this._lastItem.mouseDown(false);
                }
                this._lastItem = loc1;
            }
            return;
        }

        public updateData(arg1: Array<any>, arg2: int, arg3: int=0): void
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=null;
            this.dispose();
            if (arg1 != null) 
            {
                loc2 = arg1.length;
                while (loc1 < loc2) 
                {
                    loc3 = arg1[loc1];
                    loc4 = ObjectPool.getObject(DailyItem);
                    if (loc3 != null) 
                    {
                        loc4.updateData(loc3);
                        this._bodySprite.addItem(loc4);
                        if (loc1 == 0) 
                        {
                            this._dailyAwardList.updateData(loc3);
                            loc4.mouseDown(true);
                            this._lastItem = loc4;
                        }
                    }
                    ++loc1;
                }
                if (loc2 <= 4) 
                {
                    this._scrollPane.verticalScrollPolicy = ScrollPolicy.OFF;
                }
                else 
                {
                    this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
                }
            }
            this._bodySprite.redraw();
            this._scrollPane.refreshPane();
            this._scrollPane.update();
            this._scrollPane.horizontalScrollPosition = 0;
            this.selectedItemByType(arg3);
            if (arg2 == DailyRule.TypeEveryDay) 
            {
                this._dailyAwardList.setCheckTipsVisible(true);
            }
            return;
        }

        protected selectedItemByType(arg1: int): void
        {
            var loc1=null;
            if (arg1 != 0) 
            {
                loc1 = this._bodySprite.getItemByType(arg1);
                if (loc1 && !(loc1 == this._lastItem)) 
                {
                    loc1.mouseDown(true);
                    this._dailyAwardList.updateData(loc1.info);
                    if (this._lastItem) 
                    {
                        this._lastItem.mouseDown(false);
                    }
                    this._lastItem = loc1;
                }
            }
            return;
        }

        public onDailyActiveTimeRes(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1) 
            {
                var loc3=0;
                var loc4=arg1;
                for (loc2 in loc4) 
                {
                    loc1 = this._bodySprite.getItemByType(int(loc2));
                    if (!loc1) 
                    {
                        continue;
                    }
                    loc1.updateActiveTime(arg1[loc2]);
                }
            }
            return;
        }

        public dispose(): void
        {
            this._bodySprite.dispose();
            if (this._dailyAwardList) 
            {
                this._dailyAwardList.dispose();
            }
            this._lastItem = null;
            return;
        }

        public /* override */ get width(): number
        {
            return this._width;
        }

        public /* override */ get height(): number
        {
            return this._height;
        }

        protected /* var */_bg: ScaleBitmap;

        protected /* var */_titleBar: DailyTitleBar;

        protected /* var */_scrollPane: GScrollPane;

        protected /* var */_bodySprite: DailyListBody;

        protected /* var */_dailyAwardList: DailyAwardList;

        protected /* var */_lastItem: DailyItem;

        protected /* var */_titleWidth: int;

        protected /* var */_listWidth: int;

        protected /* var */_listHeight: int;

        protected /* var */_width: int=664;

        protected /* var */_height: int=402;
    }
